<?php

class Db_Base
{
    var $db_host;
    var $db_name;
    var $db_user;
    var $password;
    var $linkID;
    var $sql;
    var $result;
//构造函数，其中dbname，dbuser，dbpsd填自己的数据名，用户名，密码
    function __construct()
    {
        $this->linkID = 0;
        $this->sql = "";
        $this->db_name="test";
        $this->db_user="root";
        $this->password="root";
        $this->db_host="localhost";
//调用数据库链接函数
        $this->Db_Connect();

    }
    function Db_Base()
    {
        $this->__construct();
    }

//链接数据库函数
    function Db_Connect()
    {
        $this->linkID=@mysql_connect($this->db_host,$this->db_user,$this->password);
        if(!$this->linkID)
        {
            DisplayError("连接失败");exit();
        }
        $this->Db_Select();
        return true;
    }

//选择数据库函数
    function Db_Select()
    {
        $select=mysql_select_db($this->db_name);
        if(!$select)
        {
            DisplayError("选择数据库失败");exit();
        }
    }
//sql语句操作
    function Db_Query($sql)
    {
        mysql_query('SET NAMES utf-8');
        if($sql)  $this->sql=$sql;
        if(!($this->result=mysql_query($this->sql,$this->linkID)))
        {
            DisplayError("SQL无效");
            return 0;
        }
        else
        {
            return $this->result;
        }
    }
//sql语句的结果用数组返回
    function Db_Fetch_Array()
    {

        return mysql_fetch_array($this->result);

    }

    //select语句 影响的行数
    function Db_Num_Rows()
    {
        return mysql_num_rows($this->result);
    }
    //INSERT、UPDATE 、DELETE 的影响行数
    function Db_Affected_Rows()
    {
        return mysql_affected_rows();

    }
//清除记录
    function Db_Free_Result()
    {
        if(!is_array($this->result)) return "";
        foreach($this->result as $kk => $vv)
        {
            if($vv) @mysql_free_result($vv);
        }
    }



    function insertData($exec){
        mysql_query($exec);
    }

}?>